<template>
  <!-- 处理提现的弹窗 -->
  <el-dialog class="pick-dialog" :title="title" :visible.sync="dialogVisible" :close-on-click-modal="false" width="1100px">
    <div class="form-box" v-loading="loading">
      <div class="orderTable table_box">
        <el-table :data="orderList" border style="width: 100%">
          <el-table-column prop="tenantName" label="店铺"></el-table-column>
          <el-table-column prop="applicantName" label="申请人昵称"></el-table-column>
          <el-table-column prop="applicantTel" label="联系电话"></el-table-column>
          <el-table-column prop="createTime" label="申请时间"></el-table-column>
       
          <el-table-column prop="applicantAmount" label="申请金额"></el-table-column>
          <el-table-column prop="rate" label="手续费率">
            <template slot-scope="scope">
              <span>{{scope.row.rate}}%</span>
            </template>
          </el-table-column>
          <el-table-column prop="amount" label="打款金额"></el-table-column>
          <el-table-column prop="" label="账户类型">
            <template slot-scope="scope">
              <span>{{commonMaps.accountType[scope.row.accountType]}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="applicantRealName" label="账户名称"></el-table-column>
          <el-table-column prop="account" label="账号">
            <template slot-scope="scope">
              <span>{{scope.row.account}} </span>
              <div style="color:red" v-show="scope.row.isCheck==1">该账号是首次提现或与上次提现不一致，请核对后再打款！</div>
            </template>
          </el-table-column>
        </el-table>
        <div class="total-amount flex">
          <h3>打款金额：</h3>
          <div class="price">
            {{ info.amount }}元
          </div>
        </div>
      </div>
      <el-form :model="ruleForm" ref="ruleForm" label-width="80px" :rules="rules" class="demo-ruleForm">
        <el-form-item label="打款时间:" prop="sucessTime">
          <el-date-picker v-model="ruleForm.sucessTime" type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择打款时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="上传图片:" prop="afterImg">
          <el-upload :action="uploadImgUrl" list-type="picture-card" :file-list="imgShowList0" :multiple="true" :on-preview="handlePictureCardPreview" :on-success="handleUploadSuccess0" :on-remove="handleRemove0" :limit="9">
            <i class="el-icon-plus"></i>
          </el-upload>
        </el-form-item>
        <el-form-item label="补充描述:" prop="remark">
          <el-input style="width: 600px" v-model="ruleForm.remark" type="textarea" rows="5" placeholder="请输入结算补充描述..."></el-input>
        </el-form-item>
      </el-form>
      <div class="center">
        <el-button @click="close('ruleForm')">取消</el-button>
        <el-button type="danger" @click="submitForm('ruleForm',2)" :loading="loading">拒绝打款</el-button>
        <el-button type="primary" @click="submitForm('ruleForm',1)" :loading="loading">确认已打款</el-button>
      </div>
    </div>
  </el-dialog>
</template>

<script>
import billListApi from "@/api/financeCenter/billList.js";
import { formatDate } from "@/utils/index";
export default {
  name: "",
  data() {
    return {
      title: "提现结算",
      dialogVisible: false,
      loading: false,
      // 上传相关
      uploadImgUrl: "",
      imgShowList0: [],
      newImages0: [],
      imgFileList0: [],
      // end
      ruleForm: {
        sucessTime: "",
        orderIds: [],
        userId: "",
        userName: "",
        img: "",
        remark: "",
        auditState: "",
      },
      rules: {},
      from: "", //来源
      buyerOrSeller: "",
      buyers: [],
      sellers: [],
      orderList: [],
      selectOrders: [],
      totalAmount: 0, //选中项的合计总额

      info: {},
    };
  },
  created() {
    this.uploadImgUrl = process.env.VUE_APP_BASE_API + "/upload/image";
  },
  methods: {
    open(data) {
      this.loading = false;
      this.imgShowList0 = [];
      this.newImages0 = [];
      this.imgFileList0 = [];
      this.orderList = [data];
      this.info = data;
      this.ruleForm = {
        sucessTime: formatDate(new Date()),
        orderIds: [],
        userId: "",
        userName: "",
        img: "",
        remark: "",
        auditState: "",
        partyType:data.partyType 
      };
      this.ruleForm.orderIds = [data.id];
      this.ruleForm.userId = data.applicantId;
      this.ruleForm.userName = data.applicantName;
      this.dialogVisible = true;
    },
    submitForm(formName, auditState) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$confirm(
            auditState == 1
              ? "确定已完成提现打款吗？"
              : "拒绝后需要用户重新申请提现，确定拒绝吗？",
            "提示",
            {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "",
            }
          )
            .then(() => {
              // financialStatementSaleOrder
              // 组装图片附件
              // 拼接新上传的图片
              let ziliao = [];
              if (this["newImages0"] && this["newImages0"].length) {
                let newArr = [];
                this["newImages0"].forEach((img) => {
                  newArr.push({
                    name: img.name,
                    url: img.response.data.filePath,
                  });
                });
                ziliao = this["imgFileList0"].concat(newArr);
              } else {
                ziliao = this["imgFileList0"];
              }
              this.ruleForm.img = JSON.stringify(ziliao);
              this.ruleForm.auditState = auditState;
              this.loading = true;
              billListApi.tixianSettlementApi(this.ruleForm).then((res) => {
                this.dialogVisible = false;
                this.loading = false;
                if (res.code == 200) {
                  this.$message.success(res.msg);
                  this.$parent.getList();
                }
              });
            })
            .catch(() => {});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    // 上传图片相关
    // 图片预览
    handlePictureCardPreview(file) {
      this.$viewerApi({
        images: [file.url],
      });
    },
    uploadNumber(file, fileList) {
      //限制图片数量
      this.$modal.msgError("最多只能上传9张图片");
    },
    // 图片上传成功
    handleUploadSuccess0(res, file, fileList) {
      if (res.code == 200) {
        // 取得新上传的文件
        this.newImages0 = fileList.filter((t) => {
          return t.url.indexOf("blob:") > -1;
        });
      }
    },
    // 图片删除
    handleRemove0(response) {
      const that = this;
      // 1.获取将要删除图片的临时路径
      const filePath = response.url;
      // 2.找到图片对应的索引值
      this.imgFileList0.forEach(function (element, key) {
        if (element.url === filePath) {
          that.imgFileList0.splice(key, 1); //回显的图片
        }
      });
      this.newImages0.forEach(function (element, key) {
        if (element.url === filePath) {
          that.newImages0.splice(key, 1); //新上传的图片
        }
      });
    },
    close(formName) {
      this.dialogVisible = false;
    },
  },
};
</script>
<style scoped lang="scss">
.form-box {
  height: calc(100vh - 200px);
  overflow-y: auto;
}
.topBtn {
  margin-bottom: 20px;
}
.orderTable {
  margin-top: 20px;
}
.total-amount {
  line-height: 50px;
  padding-left: 15px;
}
.price {
  font-size: 24px;
  color: crimson;
}
// .names {
//   margin: 20px 0;
// }
.demo-ruleForm {
  margin-top: 20px;
  padding-right: 20px;
}

.center {
  text-align: center;
}

::v-deep .el-dialog__body {
  padding-top: 10px !important;
}

.pick-dialog >>> .el-input--medium input {
  text-align: left;
}
</style>
